package com.s666.demo.controller.api;

import com.s666.demo.common.response.ResultVO;
import com.s666.demo.exception.CommonException;
import com.s666.demo.exception.MessageRender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author lijin
 */
public abstract class BaseApiController {

    @Autowired
    MessageRender messageRender;

    /**
     * 这里的异常会覆盖掉 @ControllerAdvice 定义的异常
     * 返回json异常
     * @param e
     * @return
     */
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public ResultVO jsonExceptionHandler(Exception e) {
        CommonException ce = new CommonException("500", e.getMessage());
        return messageRender.json(ce);
    }
}

